AddCSLuaFile("cl_init.lua") 
AddCSLuaFile("shared.lua") 
include("shared.lua")

function ENT:Initialize() 
	self.Entity:PhysicsInit(SOLID_VPHYSICS)
	self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
	self.Entity:SetSolid(SOLID_NONE)
	
	self.Entity:SetCollisionGroup(COLLISION_GROUP_WEAPON)
	
	
	local phys = self:GetPhysicsObject()
	if phys and phys:IsValid() then
		phys:Wake()
	end
end

function ENT:KeyValue(k, v)

end

function ENT:PhysicsSimulate(phys, deltatime)

	--if self.Entity:IsPlayerHolding() then return SIM_NOTHING end
	
	self.CatmullRomController:CalcPerc() -- Can't be done in the parameter call or a side effect doesn't manifest properly
	
	local CurPos  = self:GetPos()
	local CurNode = self.CatmullRomController.EntityList[self.CatmullRomController.CurSegment]
	
	phys:Wake()
	
	self.PhysShadowControl.pos = self.CatmullRomController:Point()
	self.PhysShadowControl.angle = self.CatmullRomController:Angle()

	self.PhysShadowControl.deltatime = deltatime
	
	return phys:ComputeShadowControl(self.PhysShadowControl)
end

function ENT:SetPlayers(players)
	if players.IsPlayer then -- Single player
		self.Victims[1] = players
	else
		self.Victims = players
	end
	
	for _, v in pairs(self.Victims) do
		if v.IsValid and v:IsValid() and v.SetViewEntity then
			v:SetViewEntity(self.Entity)
		end
	end
end

function ENT:OnRemove()
	self.CatmullRomController.CurSegmentTimestamp = 0
	self.CatmullRomController.CurSegment = 2
	
	for _, v in pairs(self.Victims) do
		if v.IsValid and v:IsValid() and v.SetViewEntity then
			v:SetViewEntity(v)
		end
	end
end
